package com.wuyi.controller;

import com.wuyi.pojo.Follow;
import com.wuyi.pojo.bo.FollowBO;
import com.wuyi.service.FollowService;
import com.zc.utils.JSONResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.util.pattern.PathPattern;

import java.util.Set;

/**
 * @author 曾川
 * @version 1.0.0
 * @ClassName FollowController.java
 * @Description 关注粉丝
 * @createTime 2021年11月04日 20:21:00
 */
@Api(value = "关注粉丝",tags = {"用于关注粉丝的相关接口"})
@RestController
@RequestMapping("follow")
public class FollowController {

    public final static Logger logger = LoggerFactory.getLogger(PostController.class);

    @Autowired
    private FollowService followService;

    @ApiOperation(value = "查询关注列表（可对接）", notes = "查询关注列表（可对接）", httpMethod = "GET")
    @GetMapping("/queryFollowList")
    public JSONResult queryFollowList(@ApiParam(name = "userName", value = "当前登录用户名", required = true)
                                      @RequestParam String userName,
                                      @ApiParam(name = "type", value = "0：为查询我关注的人  1：查询我的粉丝", required = true)
                                      @RequestParam Integer type,
                                      @RequestParam( required = false,defaultValue = "1")Integer pageNum,
                                      @RequestParam( required = false,defaultValue = "10")Integer pageSize) {
        return JSONResult.ok(followService.queryFollowList(userName, type, pageNum, pageSize));
    }


    @ApiOperation(value = "添加关注（可对接）", notes = "添加关注（可对接）", httpMethod = "POST")
    @PostMapping("/addFollow")
    public JSONResult addFollow(@RequestBody FollowBO followBO) {

        if (StringUtils.isBlank(followBO.getFollowUserName())) {
            return JSONResult.errorMsg("关注人userName不能为空");
        }
        if (StringUtils.isBlank(followBO.getFollowedUserName())) {
            return JSONResult.errorMsg("被关注人userName不能为空");
        }
        return followService.addFollow(followBO);
    }


    @ApiOperation(value = "取消关注（可对接）", notes = "取消关注（可对接）", httpMethod = "POST")
    @PostMapping("/cancelFollow")
    public JSONResult cancelFollow(@RequestBody FollowBO followBO) {

        return followService.cancelFollow(followBO);
    }




}
